package com.oa.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.oa.entity.Mark;
import com.oa.entity.User;
import com.oa.service.UserMarkService;
import com.oa.service.UserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
@Controller
@Scope("prototype")
public class MarkAction extends ActionSupport implements ModelDriven<Mark>{
	private static final long serialVersionUID = 1L;
	@Resource(name="userMarkService")
	private UserMarkService markService;
	
	@Resource(name="userService")
	private UserService userService ;
	
	private Mark mark = new Mark();
	
	private List<Mark> markList;
	
	public List<Mark> getMarkList() {
		return markList;
	}


	public void setMarkList(List<Mark> markList) {
		this.markList = markList;
	}

	//显示所有便签
	public String list(){
		List<Mark> markList1 = markService.selectAllMak(mark.getUnique_id());
		ActionContext.getContext().put("markList", markList1);
		return "list";
	}
	//添加便签
	public String add(){
		User user2 = (User) ActionContext.getContext().getSession().get("user1");
		mark.setUser(user2);
		boolean bl = markService.UserMarkAdd(mark);
		if(bl){
			return "toList";
		}else{
			return "err";
		}
	}
	//添加便签页面
	public String addPage(){
		return "savePage";
	}
	//修改便签页面
	public String updatePage(){
		
		Mark mark1 = markService.getById(mark.getUnique_id());
		
		ActionContext.getContext().put("mark1", mark1);
		return "savePage";
	}
	//修改便签
	public String update(){
		boolean bl = markService.UserMarkUpdate(mark);
		if(bl){
			return "toList";
		}else{
			return "err";
		}
	}
	//删除便签
	public String delete(){
		boolean bl  = markService.UserMarkDelete(mark);
		System.out.println(bl);
		if(bl){
			return "toList";
		}else{
			return "err";
		}
		
	}
	
	public Mark getModel() {
		return mark;
	}

}
